package com.mogu.search.controller;


import com.mogu.entity.TBlog;
import com.mogu.search.service.SearchService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "ElasticSearch相关接口", tags = {"ElasticSearch相关接口"})
@RequestMapping(value = "/search")
public class SerachController {

    @Autowired
    private SearchService searchService;



    @RequestMapping("/selectTitle")
    public List<TBlog> getBlogByTitle(@RequestParam("title") String title){

         return searchService.getBlogByTitle(title);
    }

    @RequestMapping("/selectContent")
    public List<TBlog> getBlogByContent(@RequestParam("content") String content){

        return searchService.getBlogByContent(content);
    }

    @RequestMapping(value = "/findAll")
    public List<Object> findAll() throws IOException {
        List<Object> list = new ArrayList<>();
        List<Map<String, Object>> blogs = searchService.findAll();
        for (Map<String, Object> blog : blogs) {
            list.add(blog.get("title"));
        }
        return list;
    }
}
